package org.paradise.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Param;
import org.paradise.dao.GexchangeDao;
import org.paradise.dao.GiftDao;
import org.paradise.dao.GifttableDao;
import org.paradise.dao.VipDao;
import org.paradise.pojo.Gexchange;
import org.paradise.pojo.Gifttable;
import org.paradise.pojo.Vip;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/gifttable")
public class GifttableController {
    @Autowired
    private GifttableDao gifttableDao;
    @Autowired
    public VipDao vipDao;
    @Autowired
    private GexchangeDao gexchangeDao;
    @Autowired
    private GiftDao giftDao;
    @RequestMapping("/add")
    @ResponseBody
    public Map<String,Object> add(Gifttable gifttable) throws Exception{
        Map<String,Object> map=new HashMap<>();
        gifttableDao.add(gifttable);
        return map;
    }
    @RequestMapping("/updatejifen")
    @ResponseBody
    public Map<String,Object> updatemoney(Integer jifen,Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        vipDao.updatejifen(jifen,id);
        return map;
    }
    @RequestMapping(value = "/bathadd")
    @ResponseBody
    public Map<String, Object> bathadd(@Param("vip") Vip vip, @Param("gifttableid") Integer gifttableid) throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        System.out.println(vip.getList());
//        System.out.println(card);
//        System.out.println(name);
        gexchangeDao.bathadd(vip.getList(),gifttableid);
        map.put("result",true);
        return map;
    }
    /**
     * 购买礼品记录
     */
    @RequestMapping("/buyjilu")
    @ResponseBody
    public Map<String,Object> buyjilu(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer limit, Gifttable gifttable) throws Exception{
        Map<String,Object> map=new HashMap<>();
        Page<Gifttable> pager= PageHelper.startPage(page,limit);
        List<Gifttable> list=gifttableDao.getList(gifttable);
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        map.put("count",pager.getTotal());
        return map;
    }
    @RequestMapping("/batchDelete")
    @ResponseBody
    public Map<String,Object> batchDelete(Integer[] ids) throws Exception{
        Map<String,Object> map = new HashMap<>();
        gifttableDao.batchDelete(ids);
        map.put("result",true);
        return map;
    }
    @RequestMapping("/xiangxibatchDelete")
    @ResponseBody
    public Map<String,Object> xiangxibatchDelete(Integer[] ids) throws Exception{
        Map<String,Object> map = new HashMap<>();
        gexchangeDao.batchDelete(ids);
        map.put("result",true);
        return map;
    }
    @RequestMapping("/cardvip")
    @ResponseBody
    public Map<String,Object> cardvip(Integer gifttableid) throws Exception{
        Map<String,Object> map=new HashMap<>();
        List<Gexchange> list=gexchangeDao.getnamevip(gifttableid);
        map.put("code",0);
        map.put("msg",null);
        map.put("data",list);
        return map;
    }
    @RequestMapping("/updatejifennum")
    @ResponseBody
    public Map<String,Object> updatejifennum(Integer id) throws Exception{
        Map<String,Object> map=new HashMap<>();
        giftDao.updateduihuannum(id);
        return map;
    }
}
